package one.bugu.android.demon.ui.adapter.shop;

import android.annotation.SuppressLint;
import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import java.text.DecimalFormat;
import java.util.ArrayList;

import one.bugu.android.demon.R;
import one.bugu.android.demon.bean.MagicCalDetailBean;
import one.bugu.android.demon.ui.widget.CustomListAdapter;

/**
 * 订单管理适配器
 */
public class OrderManagerAdapter extends CustomListAdapter<MagicCalDetailBean> {

    private Context mContext;

    public OrderManagerAdapter(Context context, ArrayList<MagicCalDetailBean> objList) {
        super(context, objList);
        this.mContext = context;
    }

    @Override
    protected View lpgetView(int position, View convertView, ViewGroup parent) {
        ViewHolder mHolder = null;
        if (convertView == null) {
            convertView = View.inflate(mContext, R.layout.adapter_order_manager, null);
            mHolder = new ViewHolder(convertView);
            convertView.setTag(mHolder);
        } else {
            mHolder = (ViewHolder) convertView.getTag();
        }
        if (mObjList != null) {
            setListData(mHolder, position);
        }
        return convertView;
    }

    /**
     * 填充列表数据
     *
     * @param mHolder
     * @param position
     */
    @SuppressLint("SetTextI18n")
    private void setListData(ViewHolder mHolder, int position) {
        //分割线
        MagicCalDetailBean data = mObjList.get(position);
        mHolder.tv_order_name.setText(data.getPowerNum() + "魔法算力");
        mHolder.tv_order_time.setText(data.getCreateTime());
        mHolder.tv_order_price.setText(new DecimalFormat("###.#####").format(data.getOrderMoney()) + "ETH");
        String statusText = "";
        switch (data.getOrderState()) {
            case "10":
                statusText = "下单失败";
                break;
            case "20":
                statusText = "下单成功";
                break;
            case "30":
                statusText = "下单失败";
                break;
        }
        mHolder.tv_order_status.setText(statusText);
    }

    public static class ViewHolder {
        public View rootView;
        public ImageView iv_order_icon;
        public TextView tv_order_name;
        public TextView tv_order_time;
        public TextView tv_order_price;
        public TextView tv_order_status;

        public ViewHolder(View rootView) {
            this.rootView = rootView;
            this.iv_order_icon = (ImageView) rootView.findViewById(R.id.iv_mgc_icon);
            this.tv_order_name = (TextView) rootView.findViewById(R.id.tv_order_name);
            this.tv_order_time = (TextView) rootView.findViewById(R.id.tv_order_time);
            this.tv_order_price = (TextView) rootView.findViewById(R.id.tv_order_price);
            this.tv_order_status = (TextView) rootView.findViewById(R.id.tv_order_status);
        }

    }
}
